package com.burgeon.backend.SHOP.controller;

import com.burgeon.backend.SHOP.entity.Classify;
import com.burgeon.backend.SHOP.entity.Goods;
import com.burgeon.backend.SHOP.service.ClassifyItemService;
import com.burgeon.backend.stsutil.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("shop/classifyitem")
public class ClassifyItemController extends BaseController {

    @Autowired
    private ClassifyItemService classifyItemService;

    @RequestMapping("show")
    public ResponseResult<List<Classify>> getClassifyItem(HttpSession session) {
        String token = session.getAttribute("token").toString();
        List<Classify> data =  classifyItemService.showClassifyIstem(token);
        return new ResponseResult<List<Classify>>(SUCCESS, data);
    }
    @RequestMapping("showByClassifyItem")
    public ResponseResult<List<Goods>> getGoodsByClassifyItemId(Integer start,String classifyItemId, HttpSession session) {
        String token = session.getAttribute("token").toString();
        String discount;
        if (null != session.getAttribute("user_discount")) {
            discount = session.getAttribute("user_discount").toString();
        } else {
            discount = "1";
        }
        List<Goods> data =  classifyItemService.getGoodsByClassifyItemId(start,classifyItemId,discount,token);
        return new ResponseResult<List<Goods>>(SUCCESS, data);
    }



}
